tinyBasic v1.2
==============
  tinyBasic is a quick & dirty Tiny BASIC interpreter for Palm

    Copyleft 2005-2007 by Laurent DUVEAU
    http://www.aldweb.com/

  Source code versions available in Basic (iziBasic) and Pascal (PP, NaPP and Free Pascal)




Tiny BASIC 
----------

Tiny BASIC started out as a way to get a BASIC running in the minimum amount of memory space (~2 KBytes), because RAM used to be very expensive and home computers would only have a few KB of RAM back in the 1970's.
Here is an interesting link about Tiny BASIC: http://en.wikipedia.org/wiki/Tiny_BASIC_programming_language

Nowadays, Tiny BASIC is no more than a programming game that still a few people have fun with :-)
But, nevertheless, my work inspired some other people, including Carl Gundel, who is the author of the well-known Liberty Basic. Read the full story here: http://basicprogramming.blogspot.com/2007/01/tiny-basic-revisited.html
And play online with Carl's port of my tinyBasic here: http://www.runbasic.com/

My Tiny BASIC dialect, that I just called "tinyBasic", is similar and loosely based on the Intel 8080 Tiny BASIC written by Li Chen Wang and appearing in Doctor Dobb's Journal of Computer Calisthenics & Orthodontia in the May 1976 Vol 1, No. 5 issue. It is worth mentioning that Li Chen Wang's Tiny BASIC interpreter was released with full source code, showing the "copyleft" label for the first time, and occupied only 1.77 KBytes of memory.

The main differences between my tinyBasic dialect and Li Chen Wang's Tiny BASIC are:
- the use of float and not of integer numbers (because it is written in iziBasic, there is no need to bring a limit in this area), and the use of the integer division operation ("\") to easily get the integer part of a number;
- the no use of GOSUB/RETURN to avoid a stack (and because you can easily simulate a GOSUB/RETURN call with GOTO and a variable set to the return line);
- the addition of the LOAD/SAVE statements, for allowing to keep working on a source code;
- the addition of the HELP statement, to get an immediate onboard reminder;
- the addition of the MEM statement, to get an idea of the free remaining storage;
- the addition of the CLS statement, to clear the screen;
- the addition of the TICKS/TICKSPERSEC functions, to show how to integrate functions in the math parser and to get an idea of speed execution (benchmarking).

Note: tinyBasic's bytecode in iziBasic is 3.20 KBytes long, to be compared with the 1.77 KBytes of Li Chen Wang's Tiny BASIC.




How to install tinyBasic
------------------------

You have 3 options for a Palm device:
#1. tinyBasic.prc is the original version I wrote with iziBasic, to be run on any Palm device.
#2. tinyBasic_68k.prc is the PP version of this application, to be run on any Palm device. 
    You will also have to install the StdioLib.prc file in the case you install this version.
#3. tinyBasic_ARM.prc is the NaPP version of this application, to be run on Palm devices equiped with Palm 0S 5 only.
tinyBasic is installed like any other Palm application: by HotSync, beaming... Just install one of the 3 above files (as well as StdioLib.prc for option #2).
Eventually, if installing on a Palm device, you might want to also install Memo2tinyBas.prc (read below).

You have 2 options for a PC:
1. tinyBasic.exe is the DOS & Windows version of the application, to be run on a Windows PC 
2. If your PC runs Linux, BeOS or so, you will have to compile the Pascal source code according to the target Operating System as I do not provide the executables for these platforms.




tinyBasic language
------------------

Statements  (yeah, that's all folks!):
  BYE
  CLEAR
  CLS
  END
  GOTO <expression>
  HELP
  IF <expression> THEN <statement>
  INPUT <variable> 
  [LET] <variable>=<expression> 
  LIST [<expression>|PAUSE]
  LOAD <expression> 
  MEM
  NEW 
  PRINT <expression>|<string>[,<expression>|<string>][...][;]
  REM <anything> 
  RUN 
  SAVE <expression>

Functions (available in <expression>): 
  TICKS
  TICKSPERSEC

Variables & Expressions:
The variables allowed in tinyBasic are represented by the letters [A-Z] (A to Z), each representing a float (no strings). Expressions consist of the following operations [<=,<,=,>,>=,+,-,*,/,\] ("\" is integer division), with [*,/,\] having the highest priority, followed by [+,-], then by [<=,<,=,>,>=]. "(" and ")" may be used to group expressions. 

Source code lines:
Any number of statements can appear on a line, separated by ":".
If a line is entered without a number in front, it is executed immediately. If a nonzero number appears at the start of the line, then the line is placed into program storage in the order of that line number. If there is already a line by that number, it is replaced by the new line. If the line entered has nothing after the number (line number is alone on the line), then the given line will be deleted. 
A line is limited to 63 characters. The storage capability is of 99 lines (artificial limit).

Statements & functions quick explanations:
BYE exits the tinyBasic application.
CLEAR resets all A to Z variables to the 0 (zero) value.
CLS clears the screen.
END finishes a program and returns to the "Ready" prompt.
GOTO moves program execution to a given line number.
Trick: you can easily simulate a GOSUB/RETURN call with GOTO and a variable set to the return line. Example:
10 INPUT A : R=20 : GOTO 30
20 PRINT "A=",A : END
30 A=A+10 : GOTO R
HELP displays a quick help/reminder screen of statements & functions.
The expression in the IF statement ends up in a value (>=1 is true, <1 is false). If the condition is true the statement placed after the THEN word is executed. If it is false, the execution moves to the next line. 
INPUT stores a user input in a variable.
LET is a facultative statement to store an expression into a variable.
The stored program is listed with LIST. If the listing is long, you may pause its scrolling at each page with the PAUSE option, or display a single line providing its number.
The LOAD statement loads a program identified by its value, previously saved with the SAVE statement in the "huge" RAM storage of your Palm device. If the program value is 0 (zero), then it is considered as an autoload and autorun application, which will be launched when you launch tinyBasic.
MEM returns the number of free source code lines out of the 99 lines storage capability.
NEW empties all lines.
A PRINT statement consists of any number of variables, expressions or strings separated by commas. Although strings cannot be stored in variables, a string, consisting of characters appearing between quote marks, can be printed. 
You may write anything you want after a REM statement which is bypassed by the interpreter (the interpreter ignores everything on a line following a REM statement).
The RUN statement causes all variables to be reset to 0 (zero) and the first line of the program is executed. 
SAVE saves all stored lines to a file. If no line is stored and if the file exists, it deletes the file. So,doing "NEW : SAVE 1" will delete file 1.
The TICKS function returns the Palm OS CPU ticks value and the TICKSPERSEC one returns the number of ticks that the CPU delivers per second. I added these 2 functions for the fun of benchmarking tinyBasic with the other development tools and languages :-) Don't worry, tinyBasic is very slow! Using TICKS is also a convenient way to generate pseudo random numbers (see the Matches sample program for an example of generating pseudo random numbers).




Memo2tinyBas
------------

As it soon becomes a real pain to use the very basic editing capabilities of a Tiny Basic, and so of tinyBasic, I added this Memo2tinyBas application to easily convert a tinyBasic source code written in a Memo (in the Memo Pad application of your Palm device) to the format that can be read by tinyBasic.

To be identified as a tinyBasic source code by Memo2tinyBas, the first line of a Memo should start with "tinyBas" followed by a number which will be value to use with the LOAD statement in tinyBasic. All other characters on the first line will be ignored by Memo2tinyBas and are considered as comments. So, it is a good place to put a short description of what the program does.
All following lines in the Memo should follow the structure of a tinyBasic source code line. 
To ease the reading of the source code, empty lines are allowed and will be ignored by Memo2tinyBas.

Note #1: tinyBasic is another good and small example of a GUI & files accesses sample source code for iziBasic.
Note #2: Memo2tinyBas is not useful for the Free Pascal version (to use on PCs) because the tinyBasic source code files are just plain text files that you can easily edit with any basic text editor.




tinyBasic sample source codes
-----------------------------

I designed 4 quick and easy applications while testing tinyBasic.
1. tinyBas0 - AutoRun     : Personalized Welcome
2. tinyBas1 - Hello World : Classical 'Hello World'
3. tinyBas2 - Matches     : Marienbad Game
4. tinyBas3 - Numerus     : Roman Numerals Convertor
For the Palm setup, just install the ".pdb" files like any other file for Palm.
For the PC setup, drop the files with no extension to the same directory as where the main tinyBasic.exe file is.




Updates Description
-------------------

1.2 (09/17/07)
- recompiled this program with the latest iziBasic version 6.1 to avoid device freezes or soft resets on some devices

1.1 (04/30/07)
- minor update of iziBasic's source code to retrieve correctly values like -3 or .5 (before one had to write a=0-3 or a=0.5, when now a=-3 and a=.5 are valid entries)
- another minor update was to only accept integer values as line numbers
- ported the iziBasic source code to PP, NaPP and Free Pascal

1.0 (11/04/05)
- initial release (iziBasic source code only)
